home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / pibt32s3.arc / PIBSCREN.PAS < prev    next >
Pascal/Delphi Source File  |  1985-11-03  |  43KB  |  911 lines

  1. (*----------------------------------------------------------------------*)
  2. (*       PIBSCREN.PAS --- Screen Handling Routines for Turbo Pascal     *)
  3. (*----------------------------------------------------------------------*)
  4. (*                                                                      *)
  5. (*  Author:  Philip R. Burns                                            *)
  6. (*                                                                      *)
  7. (*  Date:    Version 1.0: January, 1985 (Part of PibMenus)              *)
  8. (*           Version 1.1: March, 1985   (Part of PibMenus)              *)
  9. (*           Version 1.2: May, 1985     (Part of PibMenus)              *)
  10. (*           Version 2.0: June, 1985    (Split from PibMenus)           *)
  11. (*           Version 3.0: October, 1985                                 *)
  12. (*           Version 3.1: October, 1985                                 *)
  13. (*           Version 3.2: November, 1985                                *)
  14. (*                                                                      *)
  15. (*  Systems: For MS-DOS on IBM PCs and close compatibles only.          *)
  16. (*           Note:  I have checked these on Zenith 151s under           *)
  17. (*                  MSDOS 2.1 and IBM PCs under PCDOS 2.0.              *)
  18. (*                                                                      *)
  19. (*  History: These routines provide a simple windowing facility for     *)
  20. (*           Turbo Pascal as well as routines for direct access to the  *)
  21. (*           screen memory area.                                        *)
  22. (*                                                                      *)
  23. (*           The windowing facility provides windows similar to those   *)
  24. (*           implemented in QMODEM by John Friel III.                   *)
  25. (*                                                                      *)
  26. (*           Version 1.0 of these routines formed part of the           *)
  27. (*           PIBMENUS.PAS include file.  These routines were split off  *)
  28. (*           into a separate PIBSCREN.PAS file at version 2.0.          *)
  29. (*                                                                      *)
  30. (*           Starting with version 3.2, PibScren uses a (hopefully)     *)
  31. (*           version-independent method for ascertaining the size       *)
  32. (*           of the current window.  The method relies on the 1-pass    *)
  33. (*           construction of Turbo, so that the standard built-in       *)
  34. (*           procedure WINDOW can be replaced by one defined here, and  *)
  35. (*           the built-in version then referred to by the name          *)
  36. (*           TurboWindow.                                               *)
  37. (*                                                                      *)
  38. (*           Suggestions for improvements or corrections are welcome.   *)
  39. (*           Please leave messages on Gene Plantz's BBS (312) 882 4145  *)
  40. (*           or Ron Fox's BBS (312) 940 6496.                           *)
  41. (*                                                                      *)
  42. (*           If you use this code in your own programs, please be nice  *)
  43. (*           and give all of us credit.                                 *)
  44. (*                                                                      *)
  45. (*----------------------------------------------------------------------*)
  46. (*                                                                      *)
  47. (*  Needs:  These routines need the include files MINMAX.PAS,           *)
  48. (*          GLOBTYPE.PAS, ASCII.PAS, and INT24.PAS. These files are not *)
  49. (*          included here, since Turbo regrettably does not allow       *)
  50. (*          nested includes.                                            *)
  51. (*                                                                      *)
  52. (*----------------------------------------------------------------------*)
  53. (*                                                                      *)
  54. (*    Note that code for stacked windows is available here.  You may    *)
  55. (*    want to modify this to use compile-time window spaces, or remove  *)
  56. (*    the current push-down stack structure.                            *)
  57. (*                                                                      *)
  58. (*----------------------------------------------------------------------*)
  59.  
  60. (*----------------------------------------------------------------------*)
  61. (*           Constants, Types, and Variables for Screen Access          *)
  62. (*----------------------------------------------------------------------*)
  63.  
  64. CONST
  65.    Color_Screen_Address   = $B800;   (* Address of color screen          *)
  66.    Mono_Screen_Address    = $B000;   (* Address of mono screen           *)
  67.    Screen_Length          = 4000;    (* 80 x 25 x 2 = screen area length *)
  68.    Max_Saved_Screen       = 5;       (* Maximum no. of saved screens     *)
  69.  
  70. TYPE
  71.                                      (* A screen image            *)
  72.  
  73.    Screen_Type       = ARRAY[ 1 .. Screen_Length ] OF BYTE;
  74.  
  75.    Screen_Ptr        = ^Screen_Image_Type;
  76.  
  77.    Screen_Image_Type = RECORD
  78.                           Screen_Image: Screen_Type;
  79.                        END;
  80.  
  81.                                               (* Screen stack entries      *)
  82.    Saved_Screen_Ptr  = ^Saved_Screen_Type;
  83.  
  84.    Saved_Screen_Type = RECORD
  85.                           Screen_Image  : Screen_Type;
  86.                           Screen_Row    : INTEGER;
  87.                           Screen_Column : INTEGER;
  88.                           Screen_X1     : INTEGER;
  89.                           Screen_Y1     : INTEGER;
  90.                           Screen_X2     : INTEGER;
  91.                           Screen_Y2     : INTEGER;
  92.                        END;
  93.  
  94. VAR
  95.                                               (* Memory-mapped screen area *)
  96.    Actual_Screen        : Screen_Ptr;
  97.                                               (* Saves screen behind menus *)
  98.  
  99.    Saved_Screen         : Saved_Screen_Ptr;
  100.  
  101.                                               (* Stack of saved screens    *)
  102.  
  103.    Saved_Screen_List    : ARRAY[ 1 .. Max_Saved_Screen ] OF Saved_Screen_Ptr;
  104.  
  105. (* STRUCTURED *) CONST
  106.                                               (* Depth of saved screen stack *)
  107.    Current_Saved_Screen : 0 .. Max_Saved_Screen = 0;
  108.  
  109.                                    (* Upper left corner of      *)
  110.                                    (* current TURBO window      *)
  111. CONST
  112.    Upper_Left_Column  : Byte = 1;
  113.    Upper_Left_Row     : Byte = 1;
  114.  
  115.                                    (* Lower right corner of     *)
  116.                                    (* current TURBO window      *)
  117. CONST
  118.    Lower_Right_Column  : Byte = 80;
  119.    Lower_Right_Row     : Byte = 25;
  120.  
  121. (*----------------------------------------------------------------------*)
  122. (*       Turbo_Window --- allow access to built-in WINDOW procedure     *)
  123. (*----------------------------------------------------------------------*)
  124.  
  125. PROCEDURE Turbo_Window( X1, Y1, X2, Y2 : INTEGER );
  126.  
  127. (*----------------------------------------------------------------------*)
  128. (*                                                                      *)
  129. (*     Procedure:  Turbo_Window                                         *)
  130. (*                                                                      *)
  131. (*     Purpose:    Allows access to built-in Turbo procedure WINDOW     *)
  132. (*                 after Window is re-defined below.                    *)
  133. (*                                                                      *)
  134. (*----------------------------------------------------------------------*)
  135.  
  136. BEGIN (* Turbo_Window *)
  137.  
  138.    Window( X1, Y1, X2, Y2 );
  139.  
  140. END   (* Turbo_Window *);
  141.  
  142. (*----------------------------------------------------------------------*)
  143. (*          Window --- Redefines Turbo's built-in WINDOW procedure      *)
  144. (*----------------------------------------------------------------------*)
  145.  
  146. PROCEDURE Window( X1, Y1, X2, Y2 : INTEGER );
  147.  
  148. (*----------------------------------------------------------------------*)
  149. (*                                                                      *)
  150. (*     Procedure:  Window                                               *)
  151. (*                                                                      *)
  152. (*     Purpose:    Redefines built-in Turbo procedure WINDOW so that    *)
  153. (*                 we can keep track of window boundaries.              *)
  154. (*                                                                      *)
  155. (*----------------------------------------------------------------------*)
  156.  
  157. BEGIN (* Window *)
  158.  
  159.    Turbo_Window( X1, Y1, X2, Y2 );
  160.  
  161.    Upper_Left_Column  := X1;
  162.    Upper_Left_Row     := Y1;
  163.    Lower_Right_Column := X2;
  164.    Lower_Right_Row    := Y2;
  165.  
  166. END   (* Window *);
  167.  
  168. (*----------------------------------------------------------------------*)
  169. (*    Color_Screen_Active --- Determine if color or mono screen         *)
  170. (*----------------------------------------------------------------------*)
  171.  
  172. FUNCTION Color_Screen_Active : BOOLEAN;
  173.  
  174. (*----------------------------------------------------------------------*)
  175. (*                                                                      *)
  176. (*     Function:   Color_Screen_Active                                  *)
  177. (*                                                                      *)
  178. (*     Purpose:    Determines if color or mono screen active            *)
  179. (*                                                                      *)
  180. (*     Calling Sequence:                                                *)
  181. (*                                                                      *)
  182. (*        Color_Active := Color_Screen_Active : BOOLEAN;                *)
  183. (*                                                                      *)
  184. (*           Color_Active --- set to TRUE if the color screen is        *)
  185. (*                            active, FALSE if the mono screen is       *)
  186. (*                            active.                                   *)
  187. (*                                                                      *)
  188. (*     Calls:   INTR                                                    *)
  189. (*                                                                      *)
  190. (*----------------------------------------------------------------------*)
  191.  
  192. VAR
  193.    Regs : RegPack;
  194.  
  195. BEGIN  (* Color_Screen_Active *)
  196.  
  197.    Regs.Ax := 15 SHL 8;
  198.  
  199.    INTR( $10 , Regs );
  200.  
  201.    Color_Screen_Active := ( Regs.Al <> 7 );
  202.  
  203. End    (* Color_Screen_Active *);
  204.  
  205. (*----------------------------------------------------------------------*)
  206. (*     Current_Video_Mode --- Determine current video mode setting      *)
  207. (*----------------------------------------------------------------------*)
  208.  
  209. FUNCTION Current_Video_Mode: INTEGER;
  210.  
  211. (*----------------------------------------------------------------------*)
  212. (*                                                                      *)
  213. (*     Function:   Current_Video_Mode                                   *)
  214. (*                                                                      *)
  215. (*     Purpose:    Gets current video mode setting from system          *)
  216. (*                                                                      *)
  217. (*     Calling Sequence:                                                *)
  218. (*                                                                      *)
  219. (*        Current_Mode := Current_Video_Mode : INTEGER;                 *)
  220. (*                                                                      *)
  221. (*           Current_Mode --- set to integer representing current       *)
  222. (*                            video mode inherited from system.         *)
  223. (*                                                                      *)
  224. (*     Calls:   INTR                                                    *)
  225. (*                                                                      *)
  226. (*----------------------------------------------------------------------*)
  227.  
  228. VAR
  229.    Regs : RegPack;
  230.  
  231. BEGIN  (* Current_Video_Mode *)
  232.  
  233.    Regs.Ax := 15 SHL 8;
  234.  
  235.    INTR( $10 , Regs );
  236.  
  237.    Current_Video_Mode := Regs.Al;
  238.  
  239. End    (* Current_Video_Mode *);
  240.  
  241. (*----------------------------------------------------------------------*)
  242. (*        Get_Screen_Address --- Get address of current screen          *)
  243. (*----------------------------------------------------------------------*)
  244.  
  245. PROCEDURE Get_Screen_Address( VAR Actual_Screen : Screen_Ptr );
  246.  
  247. (*----------------------------------------------------------------------*)
  248. (*                                                                      *)
  249. (*     Procedure:  Get_Screen_Address                                   *)
  250. (*                                                                      *)
  251. (*     Purpose:    Gets screen address for current type of display      *)
  252. (*                                                                      *)
  253. (*     Calling Sequence:                                                *)
  254. (*                                                                      *)
  255. (*        Get_Screen_Address( Var Actual_Screen : Screen_Ptr );         *)
  256. (*                                                                      *)
  257. (*           Actual_Screen --- pointer whose value receives the         *)
  258. (*                             current screen address.                  *)
  259. (*                                                                      *)
  260. (*     Calls:   Color_Screen_Active                                     *)
  261. (*              PTR                                                     *)
  262. (*                                                                      *)
  263. (*----------------------------------------------------------------------*)
  264.  
  265. BEGIN  (* Get_Screen_Address *)
  266.  
  267.    IF Color_Screen_Active THEN
  268.       Actual_Screen := PTR( Color_Screen_Address , 0 )
  269.    ELSE
  270.       Actual_Screen := PTR( Mono_Screen_Address , 0 );
  271.  
  272. END    (* Get_Screen_Address *);
  273.  
  274. (*----------------------------------------------------------------------*)
  275. (*                Video Display Control Routines                        *)
  276. (*----------------------------------------------------------------------*)
  277. (*                                                                      *)
  278. (*       RvsVideoOn  --- Turn On Reverse Video                          *)
  279. (*       RvsVideoOff --- Turn Off Reverse Video                         *)
  280. (*                                                                      *)
  281. (*----------------------------------------------------------------------*)
  282.  
  283. PROCEDURE RvsVideoOn( Foreground_Color, Background_Color : INTEGER );
  284.  
  285. BEGIN (* RvsVideoOn *)
  286.  
  287.    TextColor     ( Background_color );
  288.    TextBackGround( Foreground_color );
  289.  
  290. END   (* RvsVideoOn *);
  291.  
  292. (*----------------------------------------------------------------------*)
  293.  
  294. PROCEDURE RvsVideoOff( Foreground_Color, Background_Color : INTEGER );
  295.  
  296. BEGIN (* RvsVideoOff *)
  297.  
  298.    TextColor     ( Foreground_color );
  299.    TextBackGround( Background_color );
  300.  
  301. END   (* RvsVideoOff *);
  302.  
  303. (*----------------------------------------------------------------------*)
  304. (*            Upper_Left ---  Upper Position of current window          *)
  305. (*----------------------------------------------------------------------*)
  306.  
  307. PROCEDURE Upper_Left( VAR X1, Y1 : INTEGER );
  308.  
  309. (*----------------------------------------------------------------------*)
  310. (*                                                                      *)
  311. (*     Procedure:   Upper_Left                                          *)
  312. (*                                                                      *)
  313. (*     Purpose:     Returns upper position of current TURBO window      *)
  314. (*                                                                      *)
  315. (*     Calling Sequence:                                                *)
  316. (*                                                                      *)
  317. (*        Upper_Left( VAR X1, Y1 : INTEGER );                           *)
  318. (*                                                                      *)
  319. (*           X1   --- returned upper left column                        *)
  320. (*           Y1   --- returned upper left row                           *)
  321. (*                                                                      *)
  322. (*     Calls:   None                                                    *)
  323. (*                                                                      *)
  324. (*----------------------------------------------------------------------*)
  325.  
  326. BEGIN  (* Upper_Left *)
  327.  
  328.     Y1 := Upper_Left_Row;          (* get Row *)
  329.     X1 := Upper_Left_Column        (* get Column *)
  330.  
  331. END    (* Upper_Left *);
  332.  
  333.  
  334. (*----------------------------------------------------------------------*)
  335. (*                Set/Reset Text Color Routines                         *)
  336. (*----------------------------------------------------------------------*)
  337. (*                                                                      *)
  338. (*   These routines set and reset the global text foreground and        *)
  339. (*   background colors.                                                 *)
  340. (*                                                                      *)
  341. (*----------------------------------------------------------------------*)
  342.  
  343.                    (* Global Text Color Variables *)
  344.  
  345. VAR
  346.    Global_ForeGround_Color : INTEGER;
  347.    Global_BackGround_Color : INTEGER;
  348.  
  349. (*----------------------------------------------------------------------*)
  350. (*    Set_Global_Colors --- Reset global foreground, background cols.   *)
  351. (*----------------------------------------------------------------------*)
  352.  
  353. PROCEDURE Set_Global_Colors( ForeGround, BackGround : INTEGER );
  354.  
  355. (*----------------------------------------------------------------------*)
  356. (*                                                                      *)
  357. (*     Procedure:  Set_Global_Colors                                    *)
  358. (*                                                                      *)
  359. (*     Purpose:    Sets global text foreground, background colors.      *)
  360. (*                                                                      *)
  361. (*     Calling Sequence:                                                *)
  362. (*                                                                      *)
  363. (*        Set_Global_Colors( ForeGround, BackGround : INTEGER );        *)
  364. (*                                                                      *)
  365. (*           ForeGround --- Default foreground color                    *)
  366. (*           BackGround --- Default background color                    *)
  367. (*                                                                      *)
  368. (*     Calls:   TextColor                                               *)
  369. (*              TextBackGround                                          *)
  370. (*                                                                      *)
  371. (*----------------------------------------------------------------------*)
  372.  
  373. BEGIN  (* Set_Global_Colors *)
  374.  
  375.    Global_ForeGround_Color := ForeGround;
  376.    GLobal_BackGround_Color := BackGround;
  377.  
  378.    TextColor     ( Global_ForeGround_Color );
  379.    TextBackground( Global_BackGround_Color );
  380.  
  381. END    (* Set_Global_Colors *);
  382.  
  383. (*----------------------------------------------------------------------*)
  384. (*  Reset_Global_Colors --- Reset global foreground, background cols.   *)
  385. (*----------------------------------------------------------------------*)
  386.  
  387. PROCEDURE Reset_Global_Colors;
  388.  
  389. (*----------------------------------------------------------------------*)
  390. (*                                                                      *)
  391. (*     Procedure:  Reset_Global_Colors                                  *)
  392. (*                                                                      *)
  393. (*     Purpose:    Resets text foreground, background colors to global  *)
  394. (*                 defaults.                                            *)
  395. (*                                                                      *)
  396. (*     Calling Sequence:                                                *)
  397. (*                                                                      *)
  398. (*        Reset_Global_Colors;                                          *)
  399. (*                                                                      *)
  400. (*     Calls:   TextColor                                               *)
  401. (*              TextBackGround                                          *)
  402. (*                                                                      *)
  403. (*----------------------------------------------------------------------*)
  404.  
  405. BEGIN  (* Reset_Global_Colors *)
  406.  
  407.    TextColor     ( Global_ForeGround_Color );
  408.    TextBackground( Global_BackGround_Color );
  409.  
  410. END    (* Reset_Global_Colors *);
  411.  
  412. (*----------------------------------------------------------------------*)
  413. (*                 Screen Manipulation Routines                         *)
  414. (*----------------------------------------------------------------------*)
  415. (*                                                                      *)
  416. (*   These routines save and restore screen images in support of the    *)
  417. (*   windowing facility.  Also, the current screen image can be printed *)
  418. (*   and text extracted from the screen memory.                         *)
  419. (*                                                                      *)
  420. (*----------------------------------------------------------------------*)
  421.  
  422. (*----------------------------------------------------------------------*)
  423. (*       Get_Screen_Text_Line --- Extract text from screen image        *)
  424. (*----------------------------------------------------------------------*)
  425.  
  426. PROCEDURE Get_Screen_Text_Line( VAR Text_Line     : AnyStr;
  427.                                     Screen_Line   : INTEGER;
  428.                                     Screen_Column : INTEGER );
  429.  
  430. (*----------------------------------------------------------------------*)
  431. (*                                                                      *)
  432. (*     Procedure:  Get_Screen_Text_Line                                 *)
  433. (*                                                                      *)
  434. (*     Purpose:    Extracts text from current screen image              *)
  435. (*                                                                      *)
  436. (*     Calling Sequence:                                                *)
  437. (*                                                                      *)
  438. (*       Get_Screen_Text_Line( Var  Text_Line     : AnyStr;             *)
  439. (*                                  Screen_Line   : INTEGER;            *)
  440. (*                                  Screen_Column : INTEGER );          *)
  441. (*                                                                      *)
  442. (*           Text_Line        --- receives text extracted from screen   *)
  443. (*           Screen_Line      --- line on screen to extract             *)
  444. (*           Screen_Column    --- starting column to extract            *)
  445. (*                                                                      *)
  446. (*     Calls:   None                                                    *)
  447. (*                                                                      *)
  448. (*     Remarks:                                                         *)
  449. (*                                                                      *)
  450. (*        Only the text -- not attributes -- from the screen is         *)
  451. (*        returned.                                                     *)
  452. (*                                                                      *)
  453. (*----------------------------------------------------------------------*)
  454.  
  455. VAR
  456.    First_Pos  : INTEGER;
  457.    Last_Pos   : INTEGER;
  458.    I          : INTEGER;
  459.  
  460. BEGIN  (* Get_Screen_Text_Line *)
  461.  
  462.    Screen_Line   := Max( Min( Screen_Line   , 25 ) , 1 );
  463.    Screen_Column := Max( Min( Screen_Column , 80 ) , 1 );
  464.  
  465.    Text_Line     := '';
  466.    First_Pos     := ( ( Screen_Line - 1 ) * 80 + Screen_Column ) * 2 - 1;
  467.    Last_Pos      := First_Pos + ( 80 - Screen_Column ) * 2 + 1;
  468.  
  469.    REPEAT
  470.       Text_Line := Text_Line + CHR( Actual_Screen^.Screen_Image[ First_Pos ] );
  471.       First_Pos := First_Pos + 2;
  472.    UNTIL ( First_Pos > Last_Pos );
  473.  
  474. END    (* Get_Screen_Text_Line *);
  475.  
  476. (*----------------------------------------------------------------------*)
  477. (*                Print_Screen --- Print current screen image           *)
  478. (*----------------------------------------------------------------------*)
  479.  
  480. PROCEDURE Print_Screen;
  481.  
  482. (*----------------------------------------------------------------------*)
  483. (*                                                                      *)
  484. (*     Procedure:  Print_Screen                                         *)
  485. (*                                                                      *)
  486. (*     Purpose:    Prints current screen image (memory mapped area)     *)
  487. (*                                                                      *)
  488. (*     Calling Sequence:                                                *)
  489. (*                                                                      *)
  490. (*        Print_Screen;                                                 *)
  491. (*                                                                      *)
  492. (*     Calls:   None                                                    *)
  493. (*                                                                      *)
  494. (*     Remarks:                                                         *)
  495. (*                                                                      *)
  496. (*        Only the text from the screen is printed, not the attributes. *)
  497. (*                                                                      *)
  498. (*----------------------------------------------------------------------*)
  499.  
  500. VAR
  501.    I         : INTEGER;
  502.    Text_Line : STRING[80];
  503.  
  504. BEGIN  (* Print_Screen *)
  505.  
  506.    FOR I := 1 TO 25 DO
  507.       BEGIN
  508.          Get_Screen_Text_Line( Text_Line, I, 1 );
  509.          WRITELN( Lst , Text_Line );
  510.       END;
  511.  
  512. END    (* Print_Screen *);
  513.  
  514. (*----------------------------------------------------------------------*)
  515. (*        Write_Screen --- Write current screen image to file           *)
  516. (*----------------------------------------------------------------------*)
  517.  
  518. PROCEDURE Write_Screen( Fname : AnyStr );
  519.  
  520. (*----------------------------------------------------------------------*)
  521. (*                                                                      *)
  522. (*     Procedure:  Write_Screen                                         *)
  523. (*                                                                      *)
  524. (*     Purpose:    Write current screen image (memory mapped area) to   *)
  525. (*                 a file.                                              *)
  526. (*                                                                      *)
  527. (*     Calling Sequence:                                                *)
  528. (*                                                                      *)
  529. (*        Write_Screen( Fname : AnyStr );                               *)
  530. (*                                                                      *)
  531. (*           Fname --- Name of file to write screen to                  *)
  532. (*                                                                      *)
  533. (*     Calls:   None                                                    *)
  534. (*                                                                      *)
  535. (*     Remarks:                                                         *)
  536. (*                                                                      *)
  537. (*        Only the text from the screen is written, not the attributes. *)
  538. (*        If the file already exists, then the new screen is appended   *)
  539. (*        to the end of the file.                                       *)
  540. (*                                                                      *)
  541. (*----------------------------------------------------------------------*)
  542.  
  543. VAR
  544.    I         : INTEGER;
  545.    Text_Line : STRING[80];
  546.    F         : TEXT [512];
  547.  
  548. BEGIN  (* Write_Screen *)
  549.  
  550.       (*$I-*)
  551.    ASSIGN( F , Fname );
  552.    RESET ( F );
  553.  
  554.    IF Int24Result = 0 THEN
  555.       BEGIN
  556.          CLOSE( F );
  557.          APPEND( F );
  558.       END
  559.    ELSE
  560.       BEGIN
  561.          CLOSE  ( F );
  562.          REWRITE( F );
  563.       END;
  564.  
  565.    FOR I := 1 TO 25 DO
  566.       BEGIN
  567.          Get_Screen_Text_Line( Text_Line, I, 1 );
  568.          WRITELN( F , Text_Line );
  569.       END;
  570.  
  571.    CLOSE( F );
  572.      (*$I+*)
  573.  
  574. END    (* Write_Screen *);
  575.  
  576. (*----------------------------------------------------------------------*)
  577. (*                WriteSLin --- Write text string to screen             *)
  578. (*----------------------------------------------------------------------*)
  579.  
  580. PROCEDURE WriteSLin( S: AnyStr; Color: INTEGER );
  581.  
  582. (*----------------------------------------------------------------------*)
  583. (*                                                                      *)
  584. (*     Procedure:  WriteSLin                                            *)
  585. (*                                                                      *)
  586. (*     Purpose:    Writes text string to current line in screen memory  *)
  587. (*                                                                      *)
  588. (*     Calling Sequence:                                                *)
  589. (*                                                                      *)
  590. (*        WriteSLin( S: AnyStr; Color: INTEGER );                       *)
  591. (*                                                                      *)
  592. (*           S      --- String to be written                            *)
  593. (*           Color  --- Color in which to write string                  *)
  594. (*                                                                      *)
  595. (*     Calls:   None                                                    *)
  596. (*                                                                      *)
  597. (*----------------------------------------------------------------------*)
  598.  
  599. VAR
  600.    Length_S : INTEGER;
  601.    S_Column : INTEGER;
  602.    S_Row    : INTEGER;
  603.    I        : INTEGER;
  604.    Regs     : RegPack;
  605.  
  606. BEGIN (* WriteSLin *)
  607.  
  608.    Length_S := LENGTH( S );
  609.  
  610.    IF ( NOT Write_Screen_Memory ) THEN
  611.       BEGIN
  612.  
  613.          S_Row := WhereY;
  614.  
  615.          FOR I := 1 TO Length_S DO
  616.             BEGIN
  617.  
  618.                GoToXY( I , S_Row );
  619.  
  620.                Regs.AH := 9;
  621.                Regs.AL := ORD( S[I] );
  622.                Regs.BH := 0;
  623.                Regs.BL := Color;
  624.                Regs.CX := 1;
  625.  
  626.                INTR( $10 , Regs );
  627.  
  628.             END
  629.  
  630.       END
  631.    ELSE
  632.       BEGIN
  633.  
  634.          S_Column := 1;
  635.          S_Row    := ( WhereY - 1 ) * 160;
  636.  
  637.          FOR I := 1 TO Length_S DO
  638.             WITH Actual_Screen^ DO
  639.                BEGIN
  640.                   Screen_Image[ S_Column + S_Row ]     := ORD( COPY( S, I, 1 ) );
  641.                   Screen_Image[ S_Column + S_Row + 1 ] := Color;
  642.                   S_Column := S_Column + 2;
  643.                END;
  644.  
  645.          S_Row := S_Row + 160;
  646.  
  647.          IF S_Row > 3800 THEN
  648.             InsLine;
  649.  
  650.       END;
  651.  
  652. END   (* WriteSLin *);
  653.  
  654. (*----------------------------------------------------------------------*)
  655. (*          WriteSXY --- Write text string to specified row/column      *)
  656. (*----------------------------------------------------------------------*)
  657.  
  658. PROCEDURE WriteSXY( S: AnyStr; X: INTEGER; Y: INTEGER; Color: INTEGER );
  659.  
  660. (*----------------------------------------------------------------------*)
  661. (*                                                                      *)
  662. (*     Procedure:  WriteSXY                                             *)
  663. (*                                                                      *)
  664. (*     Purpose:    Writes text string at specified row and column       *)
  665. (*                 position on screen.                                  *)
  666. (*                                                                      *)
  667. (*     Calling Sequence:                                                *)
  668. (*                                                                      *)
  669. (*        WriteSXY( S: AnyStr; X: INTEGER; Y: INTEGER; Color: INTEGER );*)
  670. (*                                                                      *)
  671. (*           S      --- String to be written                            *)
  672. (*           X      --- Column position to write string                 *)
  673. (*           Y      --- Column position to write string                 *)
  674. (*           Color  --- Color in which to write string                  *)
  675. (*                                                                      *)
  676. (*     Calls:   None                                                    *)
  677. (*                                                                      *)
  678. (*----------------------------------------------------------------------*)
  679.  
  680. VAR
  681.    Length_S : INTEGER;
  682.    S_Column : INTEGER;
  683.    S_Row    : INTEGER;
  684.    I        : INTEGER;
  685.    S_Pos    : INTEGER;
  686.    Regs     : RegPack;
  687.  
  688. BEGIN (* WriteSXY *)
  689.  
  690.    Length_S := LENGTH( S );
  691.    S_Pos    := 0;
  692.  
  693.    IF ( NOT Write_Screen_Memory ) THEN
  694.       FOR I := 1 TO Length_S DO
  695.          BEGIN
  696.  
  697.             GoToXY( X + I - 1 , Y );
  698.  
  699.             Regs.AH := 9;
  700.             Regs.AL := ORD( S[I] );
  701.             Regs.BH := 0;
  702.             Regs.BL := Color;
  703.             Regs.CX := 1;
  704.  
  705.             INTR( $10 , Regs );
  706.  
  707.          END
  708.    ELSE
  709.       FOR I := 1 TO Length_S DO
  710.          WITH Actual_Screen^ DO
  711.             IF S_Pos < 4001 THEN
  712.                BEGIN
  713.                   S_Pos                     := ( ( Y - 1 ) * 80 + X ) * 2 - 1;
  714.                   Screen_Image[ S_Pos     ] := ORD( COPY( S, I, 1 ) );
  715.                   Screen_Image[ S_Pos + 1 ] := Color;
  716.                   X                         := X + 1;
  717.                END;
  718.  
  719. END   (* WriteSXY *);
  720.  
  721. (*----------------------------------------------------------------------*)
  722. (*   WriteCXY --- Write character to screen  at specified row/column    *)
  723. (*----------------------------------------------------------------------*)
  724.  
  725. PROCEDURE WriteCXY( C: CHAR; X: INTEGER; Y: INTEGER; Color: INTEGER );
  726.  
  727. (*----------------------------------------------------------------------*)
  728. (*                                                                      *)
  729. (*     Procedure:  WriteCXY                                             *)
  730. (*                                                                      *)
  731. (*     Purpose:    Writes a character at specified row and column       *)
  732. (*                 position on screen.                                  *)
  733. (*                                                                      *)
  734. (*     Calling Sequence:                                                *)
  735. (*                                                                      *)
  736. (*        WriteCXY( C: CHAR; X: INTEGER; Y: INTEGER; Color: INTEGER );  *)
  737. (*                                                                      *)
  738. (*           C      --- Character to be written                         *)
  739. (*           X      --- Column position to write character              *)
  740. (*           Y      --- Column position to write character              *)
  741. (*           Color  --- Color in which to write character               *)
  742. (*                                                                      *)
  743. (*     Calls:   INTR                                                    *)
  744. (*                                                                      *)
  745. (*----------------------------------------------------------------------*)
  746.  
  747. VAR
  748.    S_Pos   : INTEGER;
  749.    Regs    : RegPack;
  750.  
  751. BEGIN (* WriteCXY *)
  752.  
  753.    IF ( NOT Write_Screen_Memory ) THEN
  754.       BEGIN
  755.  
  756.          GoToXY( X , Y );
  757.  
  758.          Regs.AH := 9;
  759.          Regs.AL := ORD( C );
  760.          Regs.BH := 0;
  761.          Regs.BL := Color;
  762.          Regs.CX := 1;
  763.  
  764.          INTR( $10 , Regs );
  765.  
  766.       END
  767.    ELSE
  768.       WITH Actual_Screen^ DO
  769.          BEGIN
  770.             S_Pos                     := ( ( Y - 1 ) * 80 + X ) * 2 - 1;
  771.             Screen_Image[ S_Pos     ] := ORD( C );
  772.             Screen_Image[ S_Pos + 1 ] := Color;
  773.          END;
  774.  
  775. END   (* WriteCXY *);
  776.  
  777. (*----------------------------------------------------------------------*)
  778. (*                Save_Screen --- Save current screen image             *)
  779. (*----------------------------------------------------------------------*)
  780.  
  781. PROCEDURE Save_Screen( VAR Saved_Screen_Pointer : Saved_Screen_Ptr );
  782.  
  783. (*----------------------------------------------------------------------*)
  784. (*                                                                      *)
  785. (*     Procedure:  Save_Screen                                          *)
  786. (*                                                                      *)
  787. (*     Purpose:    Saves current screen image (memory mapped area)      *)
  788. (*                                                                      *)
  789. (*     Calling Sequence:                                                *)
  790. (*                                                                      *)
  791. (*        Save_Screen( Var Saved_Screen_Pointer : Saved_Screen_Ptr );   *)
  792. (*                                                                      *)
  793. (*           Saved_Screen_Pointer  --- pointer to record receiving      *)
  794. (*                                     screen image, window location,   *)
  795. (*                                     and current cursor location.     *)
  796. (*                                                                      *)
  797. (*     Calls:   Move                                                    *)
  798. (*              Upper_Left                                              *)
  799. (*                                                                      *)
  800. (*     Remarks:                                                         *)
  801. (*                                                                      *)
  802. (*        This version checks for stack overflow.                       *)
  803. (*                                                                      *)
  804. (*----------------------------------------------------------------------*)
  805.  
  806. BEGIN  (* Save_Screen *)
  807.                                    (* Overwrite last screen if no room *)
  808.  
  809.    IF Current_Saved_Screen >= Max_Saved_Screen THEN
  810.       Saved_Screen_Pointer := Saved_Screen_List[ Max_Saved_Screen ]
  811.    ELSE
  812.       BEGIN
  813.          Current_Saved_Screen := Current_Saved_Screen + 1;
  814.          NEW( Saved_Screen_Pointer );
  815.          Saved_Screen_List[ Current_Saved_Screen ] := Saved_Screen_Pointer;
  816.       END;
  817.  
  818.    WITH Saved_Screen_Pointer^ DO
  819.       BEGIN
  820.  
  821.          Upper_Left( Screen_X1, Screen_Y1 );
  822.  
  823.          Screen_X2     := Lower_Right_Column;
  824.          Screen_Y2     := Lower_Right_Row;
  825.  
  826.          Screen_Row    := WhereY;
  827.          Screen_Column := WhereX;
  828.  
  829.          MOVE( Actual_Screen^.Screen_Image, Screen_Image, Screen_Length );
  830.  
  831.       END;
  832.  
  833. END   (* Save_Screen *);
  834.  
  835. (*----------------------------------------------------------------------*)
  836. (*              Restore_Screen --- Restore saved screen image           *)
  837. (*----------------------------------------------------------------------*)
  838.  
  839. PROCEDURE Restore_Screen( VAR Saved_Screen_Pointer : Saved_Screen_Ptr );
  840.  
  841. (*----------------------------------------------------------------------*)
  842. (*                                                                      *)
  843. (*     Procedure:  Restore_Screen                                       *)
  844. (*                                                                      *)
  845. (*     Purpose:    Restores previously saved screen image.              *)
  846. (*                                                                      *)
  847. (*     Calling Sequence:                                                *)
  848. (*                                                                      *)
  849. (*        Restore_Screen( Var Saved_Screen_Pointer: Saved_Screen_Ptr ); *)
  850. (*                                                                      *)
  851. (*           Saved_Screen_Pointer  --- pointer to record with saved     *)
  852. (*                                     screen image, window location,   *)
  853. (*                                     and cursor location.             *)
  854. (*                                                                      *)
  855. (*     Calls:   Window                                                  *)
  856. (*              Move                                                    *)
  857. (*              GoToXY                                                  *)
  858. (*              WriteCXY                                                *)
  859. (*                                                                      *)
  860. (*     Remarks:                                                         *)
  861. (*                                                                      *)
  862. (*        All saved screen pointers from the last saved down to the     *)
  863. (*        argument pointer are popped from the saved screen list.       *)
  864. (*                                                                      *)
  865. (*----------------------------------------------------------------------*)
  866.  
  867. VAR
  868.    X: BYTE;
  869.    Y: BYTE;
  870.    I: INTEGER;
  871.  
  872. BEGIN  (* Restore_Screen *)
  873.  
  874.    WITH Saved_Screen_Pointer^ DO
  875.       BEGIN
  876.  
  877.          Window( 1, 1, 80, 25 );
  878.  
  879.          IF Write_Screen_Memory THEN
  880.             MOVE( Screen_Image, Actual_Screen^.Screen_Image, Screen_Length )
  881.          ELSE
  882.             BEGIN
  883.                I := 1;
  884.                FOR Y := 1 TO 25 DO
  885.                   FOR X := 1 TO 80 DO
  886.                      BEGIN
  887.                         WriteCXY( CHR(Screen_Image[I]), X, Y, Screen_Image[I+1] );
  888.                         I := I + 2;
  889.                      END;
  890.             END;
  891.  
  892.          Window( Screen_X1, Screen_Y1, Screen_X2, Screen_Y2 );
  893.          GoToXY( Screen_Column, Screen_Row );
  894.  
  895.       END;
  896.  
  897.    WHILE( Saved_Screen_List[ Current_Saved_Screen ] <> Saved_Screen_Pointer ) DO
  898.       BEGIN
  899.          DISPOSE( Saved_Screen_List[ Current_Saved_Screen ] );
  900.          Current_Saved_Screen := Current_Saved_Screen - 1;
  901.       END;
  902.  
  903.    IF Current_Saved_Screen > 0 THEN
  904.       Current_Saved_Screen := Current_Saved_Screen - 1;
  905.  
  906.    DISPOSE( Saved_Screen_Pointer );
  907.  
  908.    Saved_Screen_Pointer := NIL;
  909.  
  910. END    (* Restore_Screen *);
  911.